/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.usercore.service;

import com.fulihui.usercore.api.UserAddressExtService;
import com.fulihui.usercore.common.util.Errors;
import com.fulihui.usercore.core.repository.UserAddressExtRepository;
import com.fulihui.usercore.dto.UserAddressExtDTO;
import com.fulihui.usercore.request.address.ext.UserAddressExtQueryRequest;
import com.fulihui.usercore.request.address.ext.UserAddressExtSaveRequest;
import org.apache.dubbo.config.annotation.Service;
import org.near.servicesupport.result.BaseResult;
import org.near.servicesupport.result.ResultBuilder;
import org.near.servicesupport.result.TSingleResult;

import javax.annotation.Resource;

/**
 * @author zhangyingjie
 * @version $Id: v 0.1 2017年07月13日 17:38 zhangyingjie Exp $
 */
@Service(version = "1.0.0")
public class UserAddressExtServiceImpl implements UserAddressExtService {
    @Resource
    private UserAddressExtRepository userAddressExtRepository;

    @Override
    public BaseResult insert(UserAddressExtSaveRequest request) {
        boolean insert = userAddressExtRepository.insert(request.getDto());
        if (!insert) {
            return ResultBuilder.fail(BaseResult.class, Errors.UserAddressExt.SAVE_FAILED);
        }
        return ResultBuilder.succ(BaseResult.class);
    }

    @Override
    public BaseResult update(UserAddressExtSaveRequest request) {
        boolean update = userAddressExtRepository.update(request.getDto());
        if (!update) {
            return ResultBuilder.fail(BaseResult.class, Errors.UserAddressExt.UPDATE_FAILED);
        }
        return ResultBuilder.succ(BaseResult.class);
    }

    @Override
    public TSingleResult<UserAddressExtDTO> queryByUserId(UserAddressExtQueryRequest request) {

        UserAddressExtDTO userAddressExtDTO = userAddressExtRepository.queryByUserId(request.getUserId());
        return ResultBuilder.succTSingle(userAddressExtDTO);
    }
}
